<?php


class CustomizationHelper extends myHelper{

	static private $instance;
	static $backgrounds;

	private function __construct(){
		
	}


	public function getBackgrounds(){
		$item = $this->getAction()->getRoute()->getObject();

		if(!$item['picture'] || !$item['picture_second']){

		
			$item = Doctrine::getTable('Structure')->createQuery()
					->from('Structure s')
					->where('s.lft < ? and s.rgt > ? and s.level < ? and s.picture != ? and s.picture_second != ?',
							array($item['lft'],$item['rgt'],$item['level'], '""','""'))
					->orderBy('s.lft desc')
				
					->execute()
					
					->getFirst();
		}


		if($item && $item['picture'] && $item['picture_second']){
			return array( @myPicture::getInstance($item['picture'])->url(),@myPicture::getInstance($item['picture_second'])->url());
		}else{
			return array('/anima/images/body_bg.png','/anima/images/content_bg.png');
		}
		
		
	}



	static function getInstance(){
		if(!self::$instance){
			self::$instance = new CustomizationHelper();
		}

		return self::$instance;
	}


	static function back1(){

		if(!self::$backgrounds)
			self::$backgrounds = self::getInstance()->getBackgrounds();

		return self::$backgrounds[0];
	}

	static function back2(){

		if(!self::$backgrounds)
			self::$backgrounds = self::getInstance()->getBackgrounds();

		return self::$backgrounds[1];
	}

	static function dark($section = null){
		if($section){
			return variable($section['pageTitle'].'_dark');
		}
		return '#00C6FF';
	}

	static function light($section = null){
		if($section){
			return variable($section['pageTitle'].'_light');
		}
	}


	static function font($section = null){
		if($section){
			$result = variable($section['pageTitle'].'_font') == 'white' ? 'white' : 'black';

			return $result;
		}
		return 'white';
	}

	static function smallarrow($section = null){
		switch(self::font($section)){
			case 'white':
				return '/anima/images/rhead_arrow_white.png';
				break;
			case 'black':
				return '/anima/images/rhead_arrow_black.png';
				break;
			default:
				return '/anima/images/main_black_arrow.png';
		}
	}

	static function averagearrow($section = null){
		switch(self::font($section)){
			case 'white':
				return '/anima/images/small_white_arrow.png';
				break;
			case 'black':
				return '/anima/images/small_black_arrow.png';
				break;
			default:
				return '/anima/images/small_black_arrow.png';
		}
	}

	static function bigarrow($section = null){
		switch(self::font($section)){
			case 'white':
				return '/anima/images/main_white_arrow.png';
				break;
			case 'black':
				return '/anima/images/main_black_arrow.png';
				break;
			default:
				return '/anima/images/main_black_arrow.png';
		}
	}


	static function prev($section = null){
		switch(self::font($section)){
			case 'white':
				return '/anima/images/prev_white.png';
				break;
			case 'black':
				return '/anima/images/prev_black.png';
				break;
			default:
				return '/anima/images/prev_black.png';
		}
	}


	static function next($section = null){
		switch(self::font($section)){
			case 'white':
				return '/anima/images/next_white.png';
				break;
			case 'black':
				return '/anima/images/next_black.png';
				break;
			default:
				return '/anima/images/next_black.png';
		}
	}




}
